﻿<phone:PhoneApplicationPage 
    x:Class="Stopwatch.Views.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"  
    xmlns:swControls="clr-namespace:Stopwatch.Controls"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="696" 
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait"  Orientation="Portrait"
    shell:SystemTray.IsVisible="True"
    OrientationChanged="PhoneApplicationPage_OrientationChanged" 
    toolkit:TiltEffect.IsTiltEnabled="True">

    <toolkit:TransitionService.NavigationInTransition>
        <toolkit:NavigationInTransition>
            <toolkit:NavigationInTransition.Backward>
                <toolkit:TurnstileTransition Mode="BackwardIn"/>
            </toolkit:NavigationInTransition.Backward>
            <toolkit:NavigationInTransition.Forward>
                <toolkit:TurnstileTransition Mode="ForwardIn"/>
            </toolkit:NavigationInTransition.Forward>
        </toolkit:NavigationInTransition>
    </toolkit:TransitionService.NavigationInTransition>
    <toolkit:TransitionService.NavigationOutTransition>
        <toolkit:NavigationOutTransition>
            <toolkit:NavigationOutTransition.Backward>
                <toolkit:TurnstileTransition Mode="BackwardOut"/>
            </toolkit:NavigationOutTransition.Backward>
            <toolkit:NavigationOutTransition.Forward>
                <toolkit:TurnstileTransition Mode="ForwardOut"/>
            </toolkit:NavigationOutTransition.Forward>
        </toolkit:NavigationOutTransition>
    </toolkit:TransitionService.NavigationOutTransition>

    <phone:PhoneApplicationPage.Resources>
        <Style x:Key="PivotHeader" TargetType="TextBlock">
            <Setter Property="FontSize" Value="22" />
            <Setter Property="FontFamily" Value="Segoe WP Bold" />
        </Style>
        <Style x:Key="SplitTextStyle" TargetType="TextBlock">
            <Setter Property="FontSize" Value="28" />
            <Setter Property="Foreground" Value="{StaticResource PhoneSubtleBrush}" />
        </Style>
    </phone:PhoneApplicationPage.Resources>

    <Grid x:Name="LayoutRoot" Background="Transparent">
        <!--枢轴控件-->
        <controls:Pivot>
            <!--枢轴项一-->
            <controls:PivotItem>
                <controls:PivotItem.Header>
                    <TextBlock Text="STOPWATCH" Style="{StaticResource PivotHeader}"/>
                </controls:PivotItem.Header>
                <Grid Width="450">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="200" />
                        <RowDefinition Height="*" />
                        <RowDefinition Height="200" />
                    </Grid.RowDefinitions>

                    <swControls:StopwatchControl Grid.Row="0" HorizontalAlignment="Center"
                                                 Hours="{Binding Watch.Hours}"
                                                 Minutes="{Binding Watch.Minutes}"
                                                 Seconds="{Binding Watch.Seconds}"
                                                 Milliseconds="{Binding Watch.Subseconds}"
                                                 SubEnabled="{Binding SubEnabled}"
                                                 SubMinutes="{Binding SubWatch.Minutes}"
                                                 SubSeconds="{Binding SubWatch.Seconds}"
                                                 SubMilliseconds="{Binding SubWatch.Subseconds}"/>

                    <ScrollViewer x:Name="SplitItemsControlScrollViewer" 
                                  Grid.Row="1" 
                                  Width="380" 
                                  Height="190" 
                                  HorizontalAlignment="Center">
                        <ItemsControl x:Name="SplitItemsControl" ItemsSource="{Binding Splits}">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="100"/>
                                            <ColumnDefinition Width="160"/>
                                            <ColumnDefinition Width="*"/>
                                        </Grid.ColumnDefinitions>

                                        <TextBlock Grid.Column="0" HorizontalAlignment="Left" Margin="5,0,0,0"
                                                   Style="{StaticResource SplitTextStyle}"  
                                                   Text="{Binding Order}"/>

                                        <TextBlock Grid.Column="1" 
                                                   Style="{StaticResource SplitTextStyle}" 
                                                   Foreground="{StaticResource PhoneAccentBrush}"
                                                   Text="{Binding SplitTime}"/>

                                        <TextBlock Grid.Column="2" HorizontalAlignment="Right"   Margin="0,0,5,0" 
                                                   Style="{StaticResource SplitTextStyle}"
                                                   Text="{Binding OriginalTime}"/>
                                    </Grid>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </ScrollViewer>

                    <Grid Grid.Row="2">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="100"/>
                            <ColumnDefinition Width="200"/>
                            <ColumnDefinition Width="100"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>

                        <Button Grid.Column="1" Margin="8" Content="reset" VerticalAlignment="Bottom" 
                                Template="{StaticResource resetButton}" 
                                Command="{Binding WatchResetCommand}"/>

                        <Button Grid.Column="2" Margin="5" Content="start" VerticalAlignment="Bottom" 
                                Template="{StaticResource startButton}" 
                                Command="{Binding WatchStartCommand}" 
                                Visibility="{Binding StartWatchButtonVisibility}"/>

                        <Button Grid.Column="2" Margin="5" Content="pause" VerticalAlignment="Bottom" 
                                Template="{StaticResource pauseButton}" 
                                Command="{Binding WatchPauseCommand}" 
                                Visibility="{Binding PauseWatchButtonVisibility}"/>

                        <Button Grid.Column="3" Margin="8" Content="split" VerticalAlignment="Bottom" 
                                Template="{StaticResource addButton}"  
                                Command="{Binding WatchSplitCommand}"/>
                    </Grid>
                </Grid>
            </controls:PivotItem>

            <!--枢轴项二-->
            <controls:PivotItem>
                <controls:PivotItem.Header>
                    <TextBlock Text="TIMER" Style="{StaticResource PivotHeader}"/>
                </controls:PivotItem.Header>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="200"/>
                    </Grid.RowDefinitions>
                    <swControls:TimerControl Grid.Row="0" x:Name="timerControl" Height="400" Width="440" VerticalAlignment="Center" 
                                             Hours="{Binding Stoptimer.Hours}"
                                             Minutes="{Binding Stoptimer.Minutes}"
                                             Seconds="{Binding Stoptimer.Seconds}"
                                             Mode="{Binding Mode}"/>
                    <Grid Grid.Row="1">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="100"/>
                            <ColumnDefinition Width="200"/>
                            <ColumnDefinition Width="100"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>

                        <Button Grid.Column="1" Margin="8" Content="reset" VerticalAlignment="Bottom" 
                                Template="{StaticResource resetButton}" 
                                Command="{Binding TimerResetCommand}"/>

                        <Button Grid.Column="2" Margin="5" Content="start" VerticalAlignment="Bottom" 
                                Template="{StaticResource startButton}" 
                                Command="{Binding TimerStartCommand}"
                                Visibility="{Binding StartTimerButtonVisibility}"/>

                        <Button Grid.Column="2" Margin="5" Content="pause" VerticalAlignment="Bottom" 
                                Template="{StaticResource pauseButton}" 
                                Command="{Binding TimerPauseCommand}" 
                                Visibility="{Binding PauseTimerButtonVisibility}"/>
                    </Grid>
                </Grid>
            </controls:PivotItem>
        </controls:Pivot>
    </Grid>

    <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
            <shell:ApplicationBarIconButton IconUri="/Images/info.png" Text="help" Click="HelpOnClick"/>
            <shell:ApplicationBarIconButton IconUri="/Images/settings.png" Text="settings" Click="SettingsOnClick"/>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>

</phone:PhoneApplicationPage>